%
3
10
1
38
       WRITING PROGRAMS

With Applesoft BASIC, you can do
things now or you can do them
later.
^
&


When you type a statement like...
^
%
3
12
1
38
...the computer carries out your
instructions right now.  That is,
your instructions are carried out
by the computer immediately after
you press RETURN.  This is called
(logically enough) IMMEDIATE
EXECUTION.
^
&
Immediate execution is fine if
you want immediate results.
But what if you want to put
several statements together and
store them until later?
^
%
3
9
1
38
You must use DEFERRED EXECUTION
if you want to make your Apple II
save statements for later use.
^
&
Deferred execution means that you
tell the computer to store your
instructions until you give the
go-ahead to execute them.
^
&
To write an instruction in
deferred execution, simply type
a number in front of the
statement.  For instance...
^
&
When you press RETURN, nothing
happens on the screen.
But the statement is stored in
the computer's memory.
^
&

To execute the PRINT statement,
type...
^
&
The RUN command causes the
Apple II to execute all of the
statements stored in memory.
^
&
Any time you put numbers in front
of one or more statements, the
resulting lines are stored in
memory as a PROGRAM.
^
&
The number of the statement (in
this case 10) is called the LINE
NUMBER.
^
&
You can add another line by typing
another line number and a
statement.  For instance...
^
&
Please execute the new program
(the command to execute a program
is RUN).
^
%
3
8
1
38
Very good!  You just ran an
Applesoft BASIC program.
^
&
Notice that line number 10 was
executed first, and line 30 was
executed second.
^
&
BASIC executes statements in the
order of the line numbers, begin-
ning with the smallest number.
^
&
Now let's say you want to insert a
line between line 10 and line 30.
No problem!  Just type...
^
%
3
10
1
38
The line numbers indicate the
order in which the lines are
executed, so line 20 will
print between line 10 and
line 30.
^
%
3
8
1
38
Type RUN and notice that the
lines print in the order of
the line numbers.
^
%
3
9
1
38
Wonderful!  You can see that
the lines were indeed printed
in the correct order.
^
&
Now it's up to you to finish
this verse with one more PRINT
statement.  Please type your
statement on line 40.
^
%
3
7
1
38
Hey, you're really getting the
hang of it,
^
%
3
11
1
38
Every program should end with
an END statement.  The END
statement tells the computer that
the program is finished and
that it doesn't have any more
work to do.
^
%
3
7
1
38
To add the END statement, you type
a line number and the word END.
^
&
Your program is now complete.
Why don't you run it?
^
%
3
10
1
38
The computer stops when it reaches
line 50, the END statement.
Notice that END isn't printed
when the program is run because it
isn't part of a PRINT statement.
^
%
3
10
1
38
But what if you want to look
at all the program statements
after you've typed them into
memory?  It's easy.  You just
type...
^
%
3
8
1
38
The LIST command shows all of
the program lines in memory in
the correct order.
^
&
Changing and deleting program
lines is a snap.
^
&
Let's say you've decided that
your rhyme could be improved
by changing line 40.
^
&
To change the line, just type
the line number and type a new
PRINT statement.
^
&
Why not try it now. Change
line 40 by typing 40 and a new
PRINT statement.
^
%
3
8
1
38
You did it!
Now type LIST to make sure
that your program did change.
^
%
3
8
1
38
Notice that the new line 40
is substituted for the old
line 40.
^
%
3
6
1
38
Now run the new program.
^
%
3
10
1
38
You're doing VERY well!
Deleting lines is just as easy.
To delete a line, simply type
the line number of the line you
want to delete and press RETURN.
^
&
For instance, if you decide that
you don't want line 30 in your
program, you can erase it by
typing 30 and pressing RETURN.
Try erasing line 30 now.
^
%
3
7
1
38
Excellent!  Now list the
program.
^
%
3
7
1
38
You can see that you have
deleted line 30.
^
%
3
9
1
38
You may be upset that you just
lost a line of your poem. Press
RETURN and we'll do you a favor
and retype line 30 for you.
^
&
There you go.  Your program is
back to its original elegance.
^
&
The next step is to save your
program.  Press RETURN to go to
the next section, or press ESC
to go back to the menu.
^
